<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>留言板 - 登录</title>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <style>
        body {
            background-image: url("/images/登录.jpg");
            background-size: cover;
            background-repeat: no-repeat;
            padding-top: 40px;
        }

        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .loginDiv {
            max-width: 600px;
            width: 100%;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.7);
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3);
            font-size: 18px;
        }
        .form-heading {
            font-size: 32px;
            text-align: center;
            margin-bottom: 20px;
            background: linear-gradient(to right, #3366cc, #ff66cc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .loginDiv h3 {
            color: #fff;
            margin-bottom: 20px;
            background: linear-gradient(to right, #3366cc, #ff66cc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .loginDiv input[type="text"],
        .loginDiv input[type="password"] {
            background-color: rgba(255, 255, 255, 0.5);
        }

        .form-control {
            border-radius: 3px;
        }

        .checkbox {
            margin-top: 0;
        }

        .btn-primary {
            background-color: #337ab7;
            border-color: #337ab7;
        }

        .btn-primary:hover,
        .btn-primary:focus {
            background-color: #286090;
            border-color: #204d74;
        }

        .pull-right {
            float: right;
        }

        .error-message {
            color: red;
            margin-top: 10px;
        }

        /* Additional styles for WeChat QR code button */
        .wechat-login-button {
            background-color: #00bb29;
            border-color: #00bb29;
        }

        .wechat-login-button:hover,
        .wechat-login-button:focus {
            background-color: #009521;
            border-color: #00801e;
        }

        .wechat-login-button img {
            width: 100%;
            max-width: 200px;
            height: auto;
            display: none;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="loginDiv">
        <h3 class="form-heading">用户登录</h3>
        <form id="form-login" class="form-horizontal" role="form">
            <div class="form-group">
                <label for="username" class="control-label">用户名：</label>
                <div>
                    <input name="username" type="text" class="form-control" id="username" placeholder="请输入用户名">
                </div>
            </div>
            <div class="form-group">
                <label for="password" class="control-label">密码：</label>
                <div>
                    <input name="password" type="password" class="form-control" id="password" placeholder="请输入密码">
                </div>
            </div>
            <div class="form-group">
                <div>
                    <label>
                        <input type="checkbox" id="auto">自动登录
                    </label>
                </div>
            </div>
            <div class="form-group">
                <div>
                    <input id="btn-login" class="btn btn-primary" type="button" value="登录" />
                    <span class="pull-right"><small>还没有账号？</small><a href="/register.html">注册</a></span>
                </div>
            </div>
        </form>
        <div id="error-message" class="error-message"></div>
        <div id="wechat-login" class="text-center">
            <button id="wechat-login-button" class="btn wechat-login-button">微信扫码登录</button>
            <img id="wechat-code-image" src="/images/微信码.png">
        </div>
    </div>
</div>
<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
<script src="../bootstrap3/js/bootstrap.js"></script>
<script>
    $(document).ready(function() {
        $("#btn-login").click(function () {
            $.ajax({
                url: "/user/login",
                type: "post",
                data: $("#form-login").serialize(),
                dataType: "JSON",
                success: function (json) {
                    if(json.state === 200){
                        alert("登录成功");
                        location.href = "/";
                    }else{
                        alert("用户名或密码错误");
                    }
                },
                error: function (xhr) {
                    $("#error-message").text("登录时产生未知的异常" + xhr.message);
                }
            });
        });

        $("#wechat-login-button").click(function () {
            $("#wechat-code-image").toggle();
        });
    });
</script>
</body>
</html>
